<?php

/**
 * @category    H2
 * @package     
 * @subpackage  
 * @author      Nam Nguyen
 * @copyright   
 */
class View {

  /**
   *
   * @var  string
   */
  protected $_script_name;
  /**
   *
   * @var  string
   */
  protected $_script_dir;
  
  /**
   *
   * @var array $_static_vars
   */
  private static $_static_vars = array();

  /**
   *
   * @param  string  $tpl
   */
  public function __construct($script_dir, $script_name) {
    $this->setScriptDir($script_dir);
    $this->setScriptName($script_name);
  }

  /**
   * set static property for view
   * @param  string $name
   * @param  mixed  $value
   */
  public static function setStatic($name, $value) {
    self::$_static_vars[$name] = $value;
  }

  /**
   * get static propery of view
   * @param  string  $name
   * @return mixed
   */
  public static function getStatic($name) {
    return @self::$_static_vars[$name];
  }

  /**
   * set property for view
   * @param  string  $name
   * @param  midex $value
   */
  public function set($name, $value) {
    $this->{$name} = $value;
  }

  /**
   * get view property
   * @param  string $name
   * @return  mixed
   */
  public function get($name) {
    return @$this->{$name};
  }

  /**
   *
   * @param   string  $related_path_tpl
   */
  public function render($script_name =  NULL) {
    include_once $this->getScriptPath();
  }

  /**
   * get current related tpl path
   * @param  string  $tpl
   */
  public function setScriptDir($script_dir) {
    $this->_script_dir = str_replace('_Controller_', '_View_', $script_dir);
    return $this;
  }

  public function getScriptDir() {
    return $this->_script_dir;
  }

  public function setScriptName($script_name) {
    $this->_script_name = $script_name . '.tpl';
  }

  public function getScriptName() {
    return $this->_script_name;
  }

  public function getScriptPath() {
    return str_replace('_',DIRECTORY_SEPARATOR, $this->_script_dir . DIRECTORY_SEPARATOR . $this->_script_name);
  }

}